<?php 

//New DOA Interface to Database
include 'inc_DAOInterface.php';

// Check if Logon Buttoon was clicked
if (isset($_REQUEST["logout_button"])){
	session_destroy();
	session_unset();
	$_SESSION=array();
	//Refresh Website
	header("location: index.php");
}
elseif (isset($_REQUEST["username"])){
	//Read Data submitted by form to log on
	$userLogin = htmlspecialchars($_POST["username"]);
	$userPassword = htmlspecialchars(md5($_POST["password"]));

	//Verify user and password
	$connection = new DAOmySQLi();
	$result =  $connection->getLogin($userLogin, $userPassword);

	if ($result == 1) {
		$_SESSION["username"] = $userLogin;
		//Refresh to show additional menupoints
		header("location: index.php");
	}
}
?>

<nav id="nav">
	<div class="ym-wrapper">
		<div class="ym-hlist">
			<ul>
				<li
					<?php if ($current_page == 'home') { echo "class=\"active\"";} ?>>
					<a href="index.php"><?php if ($current_page == 'home') {echo "<strong>";}?>Home<?php if ($current_page == 'home') {echo "</strong>";}?></a>
				</li>
				
					<?php
					if(isset($_SESSION['username'])){ ?>						
						
						<li <?php if ($current_page == 'edit_product') { echo "class=\"active\"";} ?>><a href="edit_product.php"><?php if ($current_page == 'edit_product') {echo "<strong>";}?>Edit Product<?php if ($current_page == 'edit_product') {echo "</strong>";}?></a></li>
						<li <?php if ($current_page == 'edit_news') { echo "class=\"active\"";} ?>><a href="edit_news.php"><?php if ($current_page == 'edit_news') {echo "<strong>";}?>Edit News<?php if ($current_page == 'edit_news') {echo "</strong>";}?></a></li>
						<li <?php if ($current_page == 'login') { echo "class=\"active\"";} ?>><a href="login.php"><?php if ($current_page == 'login') {echo "<strong>";}?>Edit Login<?php if ($current_page == 'login') {echo "</strong>";}?></a></li>
						
					<?php }?>
					
				<li <?php if ($current_page == 'about') {echo "class=\"active\"";} ?>><a href="about.php"><?php if ($current_page == 'about') {echo "<strong>";}?>About<?php if ($current_page == 'about') {echo "</strong>";}?></a></li>
			</ul>
			
			<?php if (isset($_SESSION['username'])) {?>
			<form action=index.php method=post class="ym-searchform">
				<input type="submit" name="logout_button" value="Logout" class="ym-searchbutton" />
			</form>
			<?php }
			elseif (!isset($_SESSION['username'])) {?>			 
			<form action=index.php method=post class="ym-searchform">						
				<input type="text" name="username" value="Username" class="ym-searchfield" />
				<input type="password" name="password" value="*****" class="ym-searchfield" />
				<input type="submit" value="Login" class="ym-searchbutton" />
			</form>
			<?php } ?>
			
		</div>
	</div>
</nav>
